﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKRevitCode.ElmentSearchUtility.LinkDocumentSuite;
using SectionSignAndFilled.StairsRoomSection.Kit;

namespace SectionSignAndFilled.StairsRoomSection.SignElems
{
	public class DoorSign
	{
		public DoorSign(Document Doc, List<BaseLinkDocumentResultBean> lstDoorCut, List<BaseLinkDocumentResultBean> lstDoorSee, Dictionary<double, List<BaseLinkDocumentResultBean>> DicFloorBottomElevator, Line SecLine)
		{
			this.m_doc = Doc;
			this.m_DicFloorBottomElevator = new Dictionary<double, List<BaseLinkDocumentResultBean>>(DicFloorBottomElevator);
			this.m_lstDoorCut.AddRange(lstDoorCut);
			this.m_lstDoorSee.AddRange(lstDoorSee);
			this.m_SecLine = SecLine;
		}

		public bool Sign()
		{
			this.SignCut();
			this.SignSee();
			return true;
		}

		public bool SignSee()
		{
			foreach (BaseLinkDocumentResultBean baseLinkDocumentResultBean in this.m_lstDoorSee)
			{
				List<double> list = new List<double>();
				bool flag = this.GetDoorElevator(baseLinkDocumentResultBean, list);
				if (flag && list.Count != 0)
				{
					XYZ xyz = ((baseLinkDocumentResultBean.UseElement as FamilyInstance).Location as LocationPoint).Point;
					xyz = baseLinkDocumentResultBean.GetTotalTransform().OfPoint(xyz);
					double item = 0.0;
					flag = SignCommon.GetTopElevatorByFloor(xyz, this.m_DicFloorBottomElevator, this.m_SecLine, ref item);
					if (flag)
					{
						list.Add(item);
					}
					Line baseLine = Line.CreateUnbound(xyz, this.m_doc.ActiveView.UpDirection);
					SignCommon.CreateDimByElevatorAndLine(this.m_doc, list, baseLine, this.m_doc.ActiveView.RightDirection);
				}
			}
			return true;
		}

		public bool SignCut()
		{
			foreach (BaseLinkDocumentResultBean bean in this.m_lstDoorCut)
			{
				Line baseLine = null;
				XYZ zero = XYZ.Zero;
				bool flag = SignCommon.GetWindowOrDoorSignDirAndLine(this.m_doc, bean, this.m_SecLine, ref baseLine, ref zero);
				if (flag)
				{
					List<double> list = new List<double>();
					flag = this.GetDoorElevator(bean, list);
					if (flag)
					{
						SignCommon.CreateDimByElevatorAndLine(this.m_doc, list, baseLine, zero);
					}
				}
			}
			return true;
		}

		public bool GetDoorElevator(BaseLinkDocumentResultBean bean, List<double> lstElev)
		{
			Document document = bean.UseElement.Document;
			FamilyInstance familyInstance = bean.UseElement as FamilyInstance;
			Parameter parameter = familyInstance.get_Parameter(BuiltInParameter.FAMILY_LEVEL_PARAM);
			if (parameter == null)
			{
				return false;
			}
			ElementId elementId = parameter.AsElementId();
			double num = 0.0;
			if (elementId != null && elementId != ElementId.InvalidElementId)
			{
				num = (document.GetElement(elementId) as Level).Elevation;
			}
			parameter = familyInstance.get_Parameter(BuiltInParameter.INSTANCE_SILL_HEIGHT_PARAM);
			if (parameter == null)
			{
				return false;
			}
			double num2 = num + parameter.AsDouble();
			parameter = familyInstance.get_Parameter(BuiltInParameter.INSTANCE_HEAD_HEIGHT_PARAM);
			if (parameter == null)
			{
				return false;
			}
			double num3 = num + parameter.AsDouble();
			Transform totalTransform = bean.GetTotalTransform();
			num2 = SignCommon.TransformDouble(totalTransform, num2);
			num3 = SignCommon.TransformDouble(totalTransform, num3);
			lstElev.Add(num2);
			lstElev.Add(num3);
			return true;
		}

		private Document m_doc;

		private List<BaseLinkDocumentResultBean> m_lstDoorCut = new List<BaseLinkDocumentResultBean>();

		private List<BaseLinkDocumentResultBean> m_lstDoorSee = new List<BaseLinkDocumentResultBean>();

		private Line m_SecLine;

		private Dictionary<double, List<BaseLinkDocumentResultBean>> m_DicFloorBottomElevator;
	}
}
